
<template>
  <div>
    <el-table
      :data="tableData"
      style="width: 100%">
      <el-table-column
        prop="tlTicket.ticketId"
        label="车票id"
      >
      </el-table-column>
      <el-table-column
        prop="userName"
        label="用户昵称"
      >
      </el-table-column>
      <el-table-column
        prop="personName"
        label="乘车人姓名">
      </el-table-column>
      <el-table-column
        prop="tlTicket.ticketStartaddr"
        label="始发站"
       >
      </el-table-column>
      <el-table-column
        prop="tlTicket.ticketStarttime"
        label="首发时间">
      </el-table-column>
      <el-table-column
        prop="tlTicket.ticketEndaddr"
        label="终点站">
      </el-table-column>
      <el-table-column
        prop="tlTicket.ticketEndtime"
        label="到达时间">
      </el-table-column>
      <el-table-column
        prop="tlTicket.ticketPrice"
        label="票价">
      </el-table-column>
      <el-table-column
        prop="tlTicket.ticketLev"
        label="座位">
        <template slot-scope="scope"> {{
            scope.row.tlTicket.ticketLev === 0 ? '一等座' : (scope.row.tlTicket.ticketLev === 1 ? '二等座' : '无座')
          }}
        </template>
      </el-table-column>
      <el-table-column
        prop="tlTicket.ticketFlag"
        label="车票状态">
        <template slot-scope="scope"> {{
            scope.row.tlTicket.ticketFlag === 1 ? '已支付' : '未支付'
          }}
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        width="100">
        <template slot-scope="scope">
          <el-button @click="updata(scope.row)" type="success" size="small" >修改</el-button><br>
          <el-button @click="show" type="primary" size="small">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page=pageable.currentpage
      :page-sizes=pageable.pagesizes
      :page-size=pageable.pagesize
      layout="total, sizes, prev, pager, next, jumper"
      :total=pageable.total
    >
    </el-pagination>
  </div>

</template>

<script>
export default {
  data() {
    return {
      pageable:{
        currentpage:1,
        pagesizes:[5,6,7,8],
        pagesize:5,
        total:30
      },
      tableData: [
        {
          userName: '',
          personFlag:'',
          personName: '',
          tlTicket: {
            ticketId: '',
            userId: '',
            personId: '',
            ticketCarname: '',
            ticketStartaddr: '',
            ticketStarttime: '',
            ticketEndaddr: '',
            ticketEndtime: '',
            ticketFlag: '',
            ticketPrice: '',
            ticketLev: ''
          }
        }
      ],
    }
  },
  methods:{
    show(){

    },
    updata(row){
      this.$router.push({path:'/updateticket',query:{gid:row.goodsId}})

    },
    handleSizeChange(val) {
      this.pageable.pagesize=val
      this.loadFindAll()
    },
    handleCurrentChange(val) {
      this.pageable.currentpage=val
      this.loadFindAll()
    },
    loadFindAll() {
      this.$axios.get('/adminticket/findAll',{
        params:{
          page:this.pageable.currentpage,
          limit:this.pageable.pagesize
        },
      })
        .then(res => {
          console.log(res.data.data)
          if (res.data.code == 200) {
            this.pageable.total=res.data.data.total;
            this.tableData = res.data.data.records;
            this.tableData.forEach(item=>{
              if (item.tlTicket.ticketLev==0){//一等座
                if (item.personFlag == 1) {
                  item.tlTicket.ticketPrice = item.tlTicket.ticketPrice * 0.8;//学生*0.8
                }else if(item.personFlag == 2){
                  item.tlTicket.ticketPrice = item.tlTicket.ticketPrice *0.5;//儿童*0.5
                }
              }
              if (item.tlTicket.ticketLev==1||item.tlTicket.ticketLev==2) {//二等或无座
                if (item.personFlag==0){//成人
                  item.tlTicket.ticketPrice = item.tlTicket.ticketPrice * 0.8;//二等*0.8
                }
                if (item.personFlag == 1) {//乘车人是学生
                  item.tlTicket.ticketPrice = item.tlTicket.ticketPrice * 0.8 * 0.8;//二等座或者无座*0.8,学生*0.8
                }else if (item.personFlag == 2){//儿童
                  item.tlTicket.ticketPrice = item.tlTicket.ticketPrice * 0.8 * 0.5;//二等座或者无座*0.8,儿童*0.5
                }
              }
            })

          } else if (res.data.code == 222) {
            // alert("暂无订单")
          }
        })
    },
  },
  mounted() {
    this.loadFindAll()
  }
}

</script>

<style>
.el-table__header-wrapper{
  height: 125px;
  line-height: 125px;
}

</style>
